﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FaWorksSolution.MvcApplication.API.Controllers
{
    public class DBSetupController : Controller
    {
        //
        // GET: /Home/
        public ActionResult Init()
        {
            string view;
            try
            {
                DefaultContext db = new DefaultContext();
                if (!db.Database.Exists())
                {
                    db.Database.Create();
                }

                db.Database.Initialize(true);

                db.AssetsGroups.Find(Guid.Empty);
                db.AssetsFiles.Find(Guid.Empty);
                db.AssetsCdns.Find(Guid.Empty);

                db.SitemapDomains.Find(Guid.Empty);
                db.SitemapPages.Find(Guid.Empty);
                
                view = "Success";
            }
            catch (Exception ex) {
                view = "Fail:" + ex.Message;
            }

            return JavaScript(view);
        }

    }
}
